<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Chat with DeepSeek</title>
    <style>
        body { font-family: Arial, sans-serif; }
        #chat { width: 300px; height: 400px; border: 1px solid #ccc; overflow-y: scroll; padding: 10px; }
        #message { width: 200px; }
    </style>
</head>
<body>
    <div id="chat"></div>
    <input id="message" type="text" placeholder="Type a message">
    <button onclick="sendMessage()">Send</button>

    <script src="/socket.io/socket.io.js"></script>
    <script>
        const socket = io();

        // 接收消息并显示在聊天框中
        socket.on('chat message', (msg) => {
            const chat = document.getElementById('chat');
            const messageElement = document.createElement('div');
            messageElement.textContent = msg;
            chat.appendChild(messageElement);
            chat.scrollTop = chat.scrollHeight; // 滚动到底部
        });

        // 发送消息到服务器
        function sendMessage() {
            const input = document.getElementById('message');
            const message = input.value;
            if (message) {
                socket.emit('chat message', message);
                input.value = ''; // 清空输入框
            }
        }
    </script>
</body>
</html>